package com.ruoyi.web.controller.channel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.ISysChannelService;
import com.ruoyi.system.service.ISysPayloadService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/system/channel")
public class ChannelController extends BaseController {
    @Resource
    ISysChannelService iSysChannelService;
    /**
     * 获取前置贷超-渠道统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:channel:all')")
    @GetMapping("/all")
    public TableDataInfo list(SysChannel channel)
    {
        startPage();
        List<SysChannel> list = iSysChannelService.selectChannelAll(channel);
        return getDataTable(list);
    }
    /**
     * 获取渠道详细列表
     */
    @PreAuthorize("@ss.hasPermi('system:channel:detail')")
    @GetMapping("/detail")
    public TableDataInfo listdetail(SysChannel channel)
    {
        startPage();
        List<SysChannel> list = iSysChannelService.selectChannelDetail(channel);
        return getDataTable(list);
    }
    /**
     * 获取渠道管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:channel:manage')")
    @GetMapping("/manage")
    public TableDataInfo listmanage(SysChannel channel)
    {
        startPage();
        List<SysChannel> list = iSysChannelService.selectChannelManage(channel);
        return getDataTable(list);
    }
    /**
     * 获取渠道统计列表
     */
    @PreAuthorize("@ss.hasPermi('system:channel:list')")
    @GetMapping("/list")
    public TableDataInfo channellist(SysChannel channel)
    {
        startPage();
        List<SysChannel> list = iSysChannelService.selectChannelList(channel);
        return getDataTable(list);
    }
    /**
     * 获取全部渠道名称
     */
    @PreAuthorize("@ss.hasPermi('system:channel:channelnamelist')")
    @GetMapping("/channelnamelist")
    public List<SysChannel> channelnamelist()
    {
        List<SysChannel> list = iSysChannelService.selectChannelnameList();
        return list;
    }
    /**
     * 导出会员列表
     */
    @Log(title = "前置贷超渠道列表", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('system:channel:export')")
    @GetMapping("/channelallexport")
    public AjaxResult export(SysChannel channel)
    {
        List<SysChannel> list = iSysChannelService.selectChannelAll(channel);
        ExcelUtil<SysChannel> util = new ExcelUtil<SysChannel>(SysChannel.class);
        return util.exportExcel(list, "前置贷超渠道列表");
    }
    /*根据id查找渠道管理*/
    @GetMapping(value = "/manage/{channelId}")
    public SysChannel channelmanageByid(@PathVariable int channelId)
    {
        return iSysChannelService.selectChannelmanageByid(channelId);
    }
    /*添加渠道管理*/
    @PreAuthorize("@ss.hasPermi('system:channel:add')")
    @Log(title = "渠道管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysChannel channel)
    {
        /*channel.setCreateBy(SecurityUtils.getUsername());*/
        return toAjax(iSysChannelService.insertChannelmanage(channel));
    }
    /**
     * 修改渠道管理
     */
    @PreAuthorize("@ss.hasPermi('system:channel:edit')")
    @Log(title = "渠道管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysChannel channel)
    {
        /*channel.setUpdateBy(SecurityUtils.getUsername());*/
        return toAjax(iSysChannelService.updateChannelmanage(channel));
    }
    /**
     * 删除渠道管理
     */
    @PreAuthorize("@ss.hasPermi('system:channel:remove')")
    @Log(title = "渠道管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{channelId}")
    public AjaxResult remove(@PathVariable int channelId)
    {
        return toAjax(iSysChannelService.deleteChannelById(channelId));
    }
}
